﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace WeatherHistory.Data.Migrations
{
    /// <inheritdoc />
    public partial class AddedRegionTypes : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<decimal>(
                name: "Longitude",
                table: "Regions",
                type: "numeric(38,17)",
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "numeric");

            migrationBuilder.AlterColumn<decimal>(
                name: "Latitude",
                table: "Regions",
                type: "numeric(38,17)",
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "numeric");

            migrationBuilder.AddColumn<long>(
                name: "RegionTypeId",
                table: "Regions",
                type: "bigint",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "RegionTypes",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Name = table.Column<string>(type: "text", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RegionTypes", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Regions_RegionTypeId",
                table: "Regions",
                column: "RegionTypeId");

            migrationBuilder.AddForeignKey(
                name: "FK_Regions_RegionTypes_RegionTypeId",
                table: "Regions",
                column: "RegionTypeId",
                principalTable: "RegionTypes",
                principalColumn: "Id");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Regions_RegionTypes_RegionTypeId",
                table: "Regions");

            migrationBuilder.DropTable(
                name: "RegionTypes");

            migrationBuilder.DropIndex(
                name: "IX_Regions_RegionTypeId",
                table: "Regions");

            migrationBuilder.DropColumn(
                name: "RegionTypeId",
                table: "Regions");

            migrationBuilder.AlterColumn<decimal>(
                name: "Longitude",
                table: "Regions",
                type: "numeric",
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "numeric(38,17)");

            migrationBuilder.AlterColumn<decimal>(
                name: "Latitude",
                table: "Regions",
                type: "numeric",
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "numeric(38,17)");
        }
    }
}
